/** Author: David Powell
This file produces Figure 2 + Figure A11
**/


clear all
set more off



global dir "/jules/b/dpowell"
global DATA "${dir}/purdue/replication/DATA"
global OUTPUT "${dir}/purdue/replication/output"


use ${DATA}/finaldata


gen payments_per_capita = 100000*oxypayments/totpop
gen payments_per_dollar = oxypayments/totalpayments



set scheme s2color  
keep if year>=2013 & year<=2016

**data start in Aug 2013
replace payments_per_capita=payments_per_capita*12/5 if year==2013



preserve
gcollapse payments* [aw=totpop], by(nontripl  year) fast
# delimit ;
twoway (connected payments_per_capita year if nontripl==0 & year<=2016 &year>2012 , msize(vtiny) color(blue) lpattern(dash) lwidth(thick) sort yaxis(1)) (connected payments_per_capita year if nontripl==1 & year<=2016 & year>2012, lwidth(thick) msize(vtiny) color(red) sort yaxis(1))
, graphregion(color(white)) ylabel(0(50)200,nogrid) xlabel(2013(1)2016, angle(45)) xtitle("Year") ytitle("Payments ($) per 100,000" ,  axis(1))  ylabel(0(50)250) legend(label(2 "Non-Triplicate States") label(1 "Triplicate States")  rows(1) order(2 1));
gr export ${OUTPUT}/fig2a.eps, replace;



twoway (connected payments_per_dollar year if nontripl==0 & year<=2016 &year>2012 , msize(vtiny) color(blue) lpattern(dash) lwidth(thick) sort yaxis(1)) (connected payments_per_dollar year if nontripl==1 & year<=2016 & year>2012, lwidth(thick) msize(vtiny) color(red) sort yaxis(1))
, graphregion(color(white)) ylabel(0(.0001).0003,nogrid) xlabel(2013(1)2016, angle(45)) xtitle("Year") ytitle("OxyContin Payments / All Payments" ,  axis(1)) 
legend(label(2 "Non-Triplicate States") label(1 "Triplicate States")  rows(1) order(2 1));
gr export ${OUTPUT}/fig2b.eps, replace;



# delimit cr
restore




preserve
collapse payments* [aw=totpop], by(nontripl triplold  year) fast
# delimit ;
twoway (connected payments_per_dollar year if nontripl==0 & year<=2016 &year>2012 & triplold==0 , msize(vtiny) color(blue) lpattern(dash) lwidth(thick) sort yaxis(1)) 
(connected payments_per_dollar year if nontripl==1 & year<=2016 &year>2012 & triplold==1 , msize(vtiny) color(red) lpattern(solid) lwidth(thick) sort yaxis(1)) 
(connected payments_per_dollar year if nontripl==1 & year<=2016 & year>2012 & triplold==0, lwidth(thick) msize(vtiny) color(green) lpattern(dash_dot) sort yaxis(1))
, graphregion(color(white)) ylabel(,nogrid) xlabel(2013(1)2016, angle(45))  xtitle("Year") ytitle("OxyContin Payments / All Payments" ,  axis(1) height(4)) 
legend(label(3 "Never Triplicate States") label(2 "Former Triplicate States") label(1 "Triplicate States")  rows(3) order(3 2 1));
gr export ${OUTPUT}/figA11b.eps, replace;


twoway (connected payments_per_capita year if nontripl==0 & year<=2016 &year>2012 & triplold==0 , msize(vtiny) color(blue) lpattern(dash) lwidth(thick) sort yaxis(1)) 
(connected payments_per_capita year if nontripl==1 & year<=2016 &year>2012 & triplold==1 , msize(vtiny) color(red) lpattern(solid) lwidth(thick) sort yaxis(1)) 
(connected payments_per_capita year if nontripl==1 & year<=2016 & year>2012 & triplold==0, lwidth(thick) msize(vtiny) color(green) lpattern(shortdash_dot) sort yaxis(1))
, graphregion(color(white))  ylabel(,nogrid) xlabel(2013(1)2016, angle(45))  xtitle("Year") ytitle("Payments ($) per 100,000" ,  axis(1) height(4)) 
legend(label(3 "Never Triplicate States") label(2 "Former Triplicate States") label(1 "Triplicate States")  rows(3) order(3 2 1));
gr export ${OUTPUT}/figA11a.eps, replace;


# delimit cr

